﻿using IdentityExample.Adapters;
using IdentityExample.Adapters.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.AspNet.Identity;
using IdentityExample.Models;

namespace IdentityExample.Controllers
{
    [Authorize]
    public class MovieController : Controller
    {
        IMovieAdapter adapter;

        public MovieController()
        {
            adapter = new MovieDataAdapter();
        }

        // GET: Movie
        public ActionResult Index()
        {
            string userId = User.Identity.GetUserId();

            FavoriteMoviesViewModel model = adapter.GetFavoriteMoviesViewModel(userId);

            return View(model);
        }

        public ActionResult CreateUserMovie()
        {
            CreateUserMovieViewModel model = new CreateUserMovieViewModel();
            
            adapter.HydrateLookups(model);
            return View(model);
        }

        [HttpPost]
        public ActionResult CreateUserMovie(CreateUserMovieViewModel model)
        {
            model.UserId = User.Identity.GetUserId();
            adapter.CreateUserMovie(model);
            return RedirectToAction("Index");
        }
    }
}